package com.itheima.unusualDemo.studentDemo;

import java.util.Scanner;

public class ExceptionDemo3 {
    public static void main(String[] args) {
        Student s= new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名");
        String name = sc.next();
        s.setName(name);
        while(true){
            System.out.println("请输入年龄");
            String ageStr = sc.next();
            try {
                //会出现类型转换异常; NumberFormatException
                int age = Integer.parseInt(ageStr);
                //可能有年龄超出合理范围的异常;
                s.setAge(age);
                //try中没有出现异常,循环结束;
                break;
            } catch (NumberFormatException e) {
                System.out.println(e.getMessage());
            } catch ( RuntimeException e ){
                //打印 new RuntimeException("信息")中的信息;作为反馈;
                System.out.println(e.getMessage());
            }
        }
    }
}
